import React from 'react';
import { Input, Select, Row, Col } from 'antd';
import FormItem from '../../../../components/FormItem';
import { compare } from '../../../../utils/compare';
import { connect } from 'react-redux';
function mapStateToProps(state) {
  console.log(state, 'state');
  return {
    codes: {
      ...state.code,
    },
  };
}
function strategyBase(props) {
  console.log(props, 'base');
  const modes = props.codes.strategy_mode
  const { strategy_mode, name } = props.value || {};
  const layout = {
    labelCol: {
      span: 6,
    },
    wrapperCol: {
      span: 18,
    },
  };

  const formItems = [
    {
      label: {
        label: '节点名称',
        ...layout,
      },
      name: 'name',
      options: {
        initialValue: name,
        rules: [
          { required: true, message: '请输入节点名称' },
          { pattern: /^[\u4E00-\u9FA5_a-zA-Z0-9]+$/, message: '限中英文数字下划线' },
          { max: 128, message: '最长128个字符' },
        ],
      },
      component: (
        <Input
          placeholder='请填写节点名称'
          disabled={props.actionType === 'detail' || props.nameDisabled}
          style={compare(props, 'name')}
        />
      ),
    },

    {
      label: {
        label: '节点模式',
        ...layout,
      },
      name: 'strategy_mode',
      options: {
        initialValue: strategy_mode,
      },
      component: (
        <Select style={{ width: '100%', ...compare(props, 'strategy_mode') }} placeholder='请选择' disabled={true}>
          {modes &&
            modes.map((it) => {
              return (
                <Select.Option value={it.key} key={it.key}>
                  {it.value}
                </Select.Option>
              );
            })}
        </Select>
      ),
    },
  ];

  return (
    <Row type='flex' gutter={20}>
      {formItems.map((item) => {
        return (
          <Col span={12} key={item.name}>
            <FormItem form={props.form} item={item} colNum={1} />
          </Col>
        );
      })}
    </Row>
  );
}
export default connect(mapStateToProps)(strategyBase);
